def P(n):
    if n <= 1:
        return False
    for i in range(2, int(n * 0.5) + 1):
        if n % i == 0:
            return False
    return True

def N(n):
    if P(n):
        return n
    l = n - 1
    u = n + 1
    while True:
        if P(l):
            return l
        elif P(u):
            return u
        l -= 1
        u += 1

w = input().split()
if len(w) != 3:
    print("Wrong input")
else:
    d = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
    try:
        i = [d.index(x) for x in w]
        n = i[0] * 100 + i[1] * 10 + i[2]
        print(N(n))
    except ValueError:
        print("Wrong input")
